package com.lesun.warehouse.TreeUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lesun.warehouse.Tree.TreeNodeUtil;
import com.lesun.warehouse.entity.UnitsBO;
import com.lesun.warehouse.mapper.gen.UnitsMapper;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class TreeDemo {

    @Resource
    private UnitsMapper unitsMapper;

    @Test
    public void test() {

        List<UnitsBO> list = unitsMapper.selectList(
                new LambdaQueryWrapper<UnitsBO>());
        TreeUtilImpl<UnitsBO, UnitsMapper> treeUtil = new TreeUtilImpl<>(unitsMapper);
        treeUtil.setCodeFunc(bo -> bo.getCode());
        treeUtil.setParentFunc(bo -> bo.getParentCode());
        treeUtil.setListFunc(bo -> bo.getChildren());
        treeUtil.setConsumer((bo, unitsBOList)->bo.setChildren(unitsBOList));

        List<UnitsBO> tree = treeUtil.getTreeList(unitsMapper.selectList(new LambdaQueryWrapper<>()));
        System.out.println(tree);
    }
}
